﻿using RantopadService.Business;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace RantopadService.query
{
    public partial class QueryFeedBack : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BindData();
        }
        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.GridView1.PageIndex = e.NewPageIndex;
            BindData();
        }

        private void BindData()
        {
            var data = FeedBackBusiness.getAllFeedBack();
            GridView1.DataSource = data;
            GridView1.DataBind();
            LabelMsg.Text = string.Format("共{0}条数据", data.Rows.Count);
        }
        private void BindData(string wherelike)
        {
            DataTable data = FeedBackBusiness.getAllFeedBack(wherelike);
            GridView1.DataSource = data;
            GridView1.DataBind();
            LabelMsg.Text = string.Format("共{0}条数据", data.Rows.Count);

        }

        protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
        {

        }

        protected void Search_Click(object sender, EventArgs e)
        {
            BindData(TextWhereLike.Text.ToString());
        }

        protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            //GridView1.EditIndex = -1;
            //GridView1.DataBind();
        }

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            //GridView1.EditIndex = e.NewEditIndex;
            //GridView1.DataBind();

            //var name = GridView1.DataKeys[e.].Value.ToString();
        }

        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {

        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            var id = GridView1.DataKeys[e.RowIndex].Value.ToString();

            if (FeedBackBusiness.delFeedBack(id) > 0)
                Response.Write("<script>alert('删除成功！')</script>");
            else
                Response.Write("<script>alert('删除失败！')</script>");
            BindData();
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //if (e.Row.RowType == DataControlRowType.DataRow)
            //{
            //    if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
            //    {
            //        ((LinkButton)e.Row.Cells[4].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除：\"" + e.Row.Cells[0].Text + "\"吗?')");
            //    }
            //}
        }







        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
  
        }

        
        public override void VerifyRenderingInServerForm(Control control)
        {
            // Confirms that an HtmlForm control is rendered for
        }
        protected void OutToExcel_Click(object sender, EventArgs e)
        {
            Helper.ExportToExcel(this, (DataTable)GridView1.DataSource, "Users");
        } 
    }
}